#include"Manager_service_achieve.h"
#include<string.h>
using namespace std;
using namespace LB;

Manager_service_achieve::Manager_service_achieve(void)
{
	mng_file=new Manager_data_achieve;
	mng_file->load(v_managers);

}

bool Manager_service_achieve:: loginManager(int manager_id,char* password)
{
	for(unsigned int i=0;i<v_managers.size();i++)
	{
		if(v_managers[i].m_id==manager_id)
		{
			if(0==strcmp(v_managers[i].m_password,password))
			{
				return true;
			}
			return false;
		}
	}
	return false;
} 

bool Manager_service_achieve:: addManager(Manager &manager)
{
	v_managers.push_back(manager);
	return true;
}

bool Manager_service_achieve:: delManager(int manager_id) 
{
	vector<Manager>::iterator  p=v_managers.begin();
	for(unsigned int i=0;i<v_managers.size();i++,p++)
	{
		if(v_managers[i].m_id==manager_id)
		{
			v_managers.erase(p);
			return true;
		}
	}
	return false;
	
}

void Manager_service_achieve::listManager(void)
{
	for (unsigned int i = 0; i <v_managers.size();i++)
	{
		cout<<v_managers[i]<<endl;
	}
}

Manager_service_achieve::~Manager_service_achieve(void)
{
	mng_file->save(v_managers);
	delete mng_file;
} 